const mysql = require('mysql');

const pool = mysql.createPool({
	//host     :  'rds4708143912z8xw567.mysql.rds.aliyuncs.com',
	//user     :  'gugong',
	//password :  'mRr5MbKndHv8tGMX',
	//port: '3306',
	//database :  'gugong'
	host     :  'localhost',
	user     :  'root',
	password :  '1',
	//port: '3306',
	database :  'gugongdb'
});


module.exports =  function( sql, values ) {
	return new Promise(( resolve, reject ) => {
		pool.getConnection(function(err, connection) {
			if (err) {
				console.log( err );
				//throw err;
				resolve( err );
			} else {
				connection.query(sql, values, ( err, rows) => {
					if ( err ) {
						console.log( err );
						//throw err;
						reject( err );
					} else {
						resolve( rows );
					}
					connection.release();
				});
			}
		});
	});
};
